/*
 * Copyright (c) 2007 jNetX.
 * http://www.jnetx.com
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * jNetX. You shall not disclose such Confidential Information and
 * shall use it only in accordance with the terms of the license
 * agreement you entered into with jNetX.
 *
 * $Id$
 */
package com.jnetx.javax.sip.header;

import javax.sip.InvalidArgumentException;
import javax.sip.header.MimeVersionHeader;

/**
 * SIP messages MAY include a single MIME-Version general-header field to
 * indicate what version of the MIME protocol was used to construct the
 * message. Use of the MIME-Version header field indicates that the message is
 * in full compliance with the MIME protocol as defined in
 * <a href = "http://www.ietf.org/rfc/rfc2405.txt">RFC2045</a>. Proxies/gateways
 * are responsible for ensuring full compliance (where possible) when exporting
 * SIP messages to strict MIME environments.
 * <p/>
 * For Example:<br>
 * <code>MIME-Version: 1.0</code>
 *
 * @author <a href="mailto:dparhonin@jnetx.ru">Dmitry Parhonin</a>
 * @version $Revision$
 */
public class MimeVersionHeaderImpl extends HeaderBase implements MimeVersionHeader {
    private int majorVersion;
    private int minorVersion;

    private static final MimeVersionHeaderParser parser = new MimeVersionHeaderParser();

    public MimeVersionHeaderImpl() {
        super(MimeVersionHeader.NAME);
    }

    MimeVersionHeaderImpl(byte[] data, int start, int end) {
        super(MimeVersionHeader.NAME, data, start, end);
    }

    public Object clone() {
        final MimeVersionHeaderImpl header = new MimeVersionHeaderImpl();
        header.cloneBase(this);
        if (parsed) {
            header.majorVersion = this.majorVersion;
            header.minorVersion = this.minorVersion;
        }
        return header;
    }

    protected HeaderParser getParser() {
        return parser;
    }

    protected String getValueAsString() {
        return Integer.toString(majorVersion) + '.' + Integer.toString(minorVersion);
    }

    /**
     * Gets the Minor version value of this MimeVersionHeader.
     *
     * @return the Minor version of this MimeVersionHeader
     */
    public int getMinorVersion() {
        parse();
        return minorVersion;
    }

    /**
     * Sets the Minor-Version argument of this MimeVersionHeader to the supplied
     * minorVersion value.
     *
     * @param minorVersion the new minor MIME version
     * @throws javax.sip.InvalidArgumentException
     *          if the supplied value is less than zero.
     */
    public void setMinorVersion(int minorVersion) throws InvalidArgumentException {
        parse();
        this.minorVersion = minorVersion;
        invalidateHeaderData();
    }

    /**
     * Gets the Major version value of this MimeVersionHeader.
     *
     * @return the Major version of this MimeVersionHeader
     */
    public int getMajorVersion() {
        parse();
        return this.majorVersion;
    }

    /**
     * Sets the Major-Version argument of this MimeVersionHeader to the supplied
     * majorVersion value.
     *
     * @param majorVersion the new major MIME version
     * @throws javax.sip.InvalidArgumentException
     *          if the supplied version is less than zero.
     */
    public void setMajorVersion(int majorVersion) throws InvalidArgumentException {
        parse();
        this.majorVersion = majorVersion;
        invalidateHeaderData();
    }
}
/*
 * $Log$
 */